#!/bin/bash

function usage()   #show how to use this shell
{
    printf "usage: bash FILE.SH \033[32m[-h|--help] [-c|--clean] [-m|--move]\033[0m \n"
    printf "                    \033[32m[-b|--build]\033[0m \n"
    printf "optional arguments:\n"
    printf "\033[32m  -h, --help              search for help information\033[0m\n"
    printf "\033[32m  -b, --build             building package ...\033[0m\n"
    printf "\033[32m  -c, --clean             aos make clean and list files\033[0m\n"
    printf "\033[32m  -m, --move              mv -f smartoutlet to filename\033[0m\n\n"
    exit 0
}

if [[ $# < 1 ]];then
    printf "Try 'bash [FILE.SH] --help' for more information.\n"
    exit
fi

while [ $# -gt 0 ]
do
    case $1 in
    -h|--help)
        usage
    ;;
    -b|--build)
        ./build.sh
    ;;
    -c|--clean)
        printf "The Output Information...\n"
        examples=`ls Products/example/`
        app_name=`cat Products/example/smart_outlet/.git/config | grep url | awk '{gsub(/^\s+|\s+$/,"");print}'`
        app_version=`cat Products/example/smart_outlet/smart_outlet.mk | grep app-`
        HF_MODULE_ID=`cat  Living_SDK/board/tg7100cevb/hfilop/hfilop.h | grep HF_MODULE_ID | awk '{print $3}'`
        printf "list files --->\n"
        printf "\033[32m${examples}\033[0m\n"
        printf "list config --->\n"
        printf "\033[32m${app_name}\033[0m\n"
        printf "\033[32m${app_version}\033[0m\n"
        printf "aos make clean --->\n"
        cd Living_SDK/ ; aos make clean ; cd ..
        printf "hfilop macro --->\n"
        printf "HF_MODULE_ID is \033[32m${HF_MODULE_ID}\033[0m\n"
    ;;
    -m|--move)
        cd Products/example/
        read -ep "Input the move source file name: " src_file_name
        read -ep "Input the move destination file name: " dest_file_name
        mv -f ${src_file_name} ${dest_file_name}
        cd ../..
        examples=`ls Products/example/`
        printf "list files:\n"
        printf "\033[32m${examples}\033[0m\n"
    ;;
    esac
    shift
done
